package br.com.gui;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import br.com.modelo.entidade.Caracteristica;
import br.com.modelo.entidade.MenuPrincipal;
import br.com.modelo.repositorio.CarregaListas;

public class MenuPrincipalTela extends Activity implements OnClickListener {

	public static ArrayList<Caracteristica> dadosXml;
	ArrayList<Button> bts = new ArrayList<Button>();
	public static String tipo, titulo;
	List<?> menus; Button bt;
	public Map<String, String> map;
	LinearLayout lyPersonalizado;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		lyPersonalizado = new LinearLayout(this);  
		lyPersonalizado.setOrientation(LinearLayout.VERTICAL);

		ScrollView s = new ScrollView(this);  
		s.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		
		map = new HashMap<String, String>();
		//mapa.put( acao , Classe);
		map.put("Residencial Horizontal", "br.com.gui.MenuRh");
		map.put("Residencial Vertical", "br.com.gui.MenuRv");
		map.put("Nao Residencial Horizontal", "br.com.gui.MenuNrh");
		map.put("Nao Residencial Vertical", "br.com.gui.MenuNrv");
		map.put("Galpao Fechado", "br.com.gui.MenuGf");
		map.put("Galpao Aberto", "br.com.gui.MenuGa");

		
			for (int c = 0; c < CarregaListas.menuP.size(); c++) {	
				bt = new Button(this);
				bt.setText(CarregaListas.menuP.get(c).getNome()); 
				bt.setId(CarregaListas.menuP.get(c).getId());				
				bt.setTextSize(11);
				bt.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));				
				bt.setOnClickListener(this);
				bts.add(bt);
				lyPersonalizado.addView(bt);							
			}
			for(int l = 0; l < bts.size();l++){
				if (bts.get(l).getText().equals("Residencial Horizontal")) {
					bts.get(l).setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.rh, 0, 0);
				}
				if (bts.get(l).getText().equals("Residencial Vertical")) {
					bts.get(l).setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.rv, 0, 0);
				}
				if (bts.get(l).getText().equals("Nao Residencial Horizontal")) {
					bts.get(l).setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.nrh_, 0, 0);
				}	
				if (bts.get(l).getText().equals("Nao Residencial Vertical")) {
					bts.get(l).setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.nrv, 0, 0);
				}
				if (bts.get(l).getText().equals("Galpao Fechado")) {
					bts.get(l).setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.gf, 0, 0);
				}
				if (bts.get(l).getText().equals("Galpao Aberto")) {
					bts.get(l).setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.gf, 0, 0);
				}

			}
			requestWindowFeature(Window.FEATURE_NO_TITLE);
			getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
					WindowManager.LayoutParams.FLAG_FULLSCREEN);
			s.addView(lyPersonalizado);
			setContentView(s);		 
	}
	@Override
	protected void onResume() {
		dadosXml = new ArrayList<Caracteristica>();
		super.onResume();
	}

	/**
	 * public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.menu_principal, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.btRh:
			startActivity(new Intent(KaritzaActivity.this,MenuPrincipal.class));
			return true;
		case R.id.btRv:

			return true;	         
		case R.id.btGf:

			return true;
		case R.id.btNrh:

			return true;
		case R.id.btNrv:

			return true;
		default:
			return super.onOptionsItemSelected(item);
		}
	}
	 */

	public void onClick(View v) {

		for(int i =0; i < bts.size();i++){
			String tela = "";
			if(bts.get(i).isPressed() == true){
				tela = bts.get(i).getText().toString();
				try {
					startActivity(new Intent(MenuPrincipalTela.this,Class.forName(map.get(tela))));
					MenuPrincipal.setId_menuPrincipal(bts.get(i).getId());
					break;
				} catch (ClassNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}				
	}
}
